package com.liangzi.service_core.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liangzi.liangzi_common.result.R;
import com.liangzi.liangzi_common.util.ArgumentEnum;
import com.liangzi.service_core.pojo.entity.InnerDoctor;
import com.liangzi.service_core.pojo.entity.InnerDoctorWork;
import com.liangzi.service_core.pojo.vo.InnerDoctorVO;
import com.liangzi.service_core.service.InnerDoctorService;
import com.liangzi.service_core.service.InnerDoctorWorkService;
import com.liangzi.servicebase.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 医生表 前端控制器
 * </p>
 *
 * @author zhj
 * @since 2021-12-13
 */
@Api(description = "医生接口")
@RestController
@RequestMapping("/web/innerDoctor")
@Slf4j
public class InnerDoctorController {

    @Autowired
    public InnerDoctorService innerDoctorService;
    @Autowired
    public InnerDoctorWorkService innerDoctorWorkService;
    @Autowired
    public RedisUtil redisUtil;

     // 根据门诊id获取所有的医生列表
    @ApiOperation(value = "根据门诊 dictCode  获取所有医生 ")
    @GetMapping("getAllDoctorList/{rdSession}/{dictCode}")
    public R getAllDoctorList(
            @PathVariable String rdSession,
            @PathVariable Long dictCode) {
        // 判断是否登录
        String userId = (String) redisUtil.get("session:" + rdSession);
        if (userId == null) {
            return  R.error().message("请重新登录");
        }
        List<InnerDoctor> doctorList = innerDoctorService.getDoctorsByDictCode(dictCode);
        return doctorList != null ?R.ok().data("records", doctorList):R.error().message("请输入正确的"+ dictCode);
    }

    // 根据医生id获取医生信息
    @ApiOperation(value = "根据医生id获取医生信息 ")
    @GetMapping("getDoctor/{rdSession}/{id}")
    public R getAllDoctorList(
            @PathVariable String rdSession,
            @PathVariable String id) {
        // 判断是否登录
        String userId = (String) redisUtil.get("session:" + rdSession);
        if (userId == null) {
            return R.error().message("请重新登录");
        }
        InnerDoctor doctor = innerDoctorService.getById(id);
        return doctor == null ? R.error().message("此医生" + id + "不存在") : R.ok().data("doctor", doctor);
    }





}

